package edu.xust.space.controller;

import edu.xust.space.mapper.CmarticleMapper;
import edu.xust.space.mapper.ProductMapper;
import edu.xust.space.pojo.Cmarticle;
import edu.xust.space.pojo.Productinfo;
import edu.xust.space.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class ViewController {
    @Autowired
    ProductMapper productMapper;
    @Autowired
    CmarticleMapper cmarticleMapper;
    @Autowired
    ProductService productService;
    @RequestMapping("/")
    public String indexView(Model model){
        //获得一个产品信息
        Productinfo ranOneProduct = productService.getRanOneProduct();
        //获取资讯信息
        List<Cmarticle> allCmarticle = cmarticleMapper.getAllCmarticle("b2fa8194-1c71-4629-ae09-b9a0ef68ba55");//行业资讯
        model.addAttribute("product",ranOneProduct);
        model.addAttribute("articles",allCmarticle);
        return "index";
    }

    @RequestMapping("/product")
    public String productView(){
        return "product";
    }
    @RequestMapping("/find")
    public String fineView(Model model){
        //行业资讯
        List<Cmarticle> allCmarticle = cmarticleMapper.getAllCmarticle("b2fa8194-1c71-4629-ae09-b9a0ef68ba55");//行业资讯
        //研究院动态
        List<Cmarticle> research  = cmarticleMapper.getAllCmarticle("0af45c58-caa4-46cf-b9a8-19d724e0b731");//研究院动态
        //学习园地
        List<Cmarticle> learn  = cmarticleMapper.getAllCmarticle("1f5168f7-78f2-4438-ad41-7dc30557f971");//学习园地
        model.addAttribute("articles",allCmarticle);
        model.addAttribute("researchs",research);
        model.addAttribute("learns",learn);
        return "find";
    }

    @RequestMapping("/mine")
    public String mineView(){
        return "mine";
    }

    @RequestMapping("/sel")
    public String selView(Model model){
        List<Productinfo> list = productMapper.getProductDetilByName("供电模块");
        model.addAttribute("infos",list);
        return "sel";
    }
}
